Merge pull request #10355 from geoffsim/MSP-VTX
[inav.git] / docs / development / Hardware Debugging in Eclipse.md
bloba8d77e22e1cbaddbf044e37789543db7f935e8c5
1 # Hardware Debugging In Eclipse
3 Build a binary with debugging information using command line or via Eclipse make target.
5 Example Eclipse make target
7 ![](https://raw.github.com/wiki/hydra/cleanflight/images/eclipse-gdb-debugging/make 1 - OLIMEXINO GDB.PNG)
9 # GDB and OpenOCD
11 start openocd
13 Create a new debug configuration in eclipse :
14 ![connect to openocd](http://i.imgur.com/somJLnq.png)
15 ![use workspace default](http://i.imgur.com/LTtioaF.png)
17 you can control openocd with a telnet connection:
19      telnet localhost 4444
21 stop the board, flash the firmware, restart:
23      reset halt
24      wait_halt 
25      sleep 100
26      poll
27      flash probe 0
28      flash write_image erase /home/user/git/inav/obj/inav_SPRACINGF3.hex 0x08000000
29      sleep 200
30      soft_reset_halt
31      wait_halt
32      poll
33      reset halt
35 A this point you can launch the debug in Eclispe.
36 ![](http://i.imgur.com/u7wDgxv.png)
38 # GDB and J Link
40 Here are some screenshots showing Hydra's configuration of Eclipse (Kepler)
42 If you use cygwin to build the binaries then be sure to have configured your common `Source Lookup Path`, `Path Mappings` first, like this:
44 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 7.PNG)
47 Create a new `GDB Hardware Debugging` launch configuration from the `Run` menu
49 It's important to have build the executable compiled with GDB debugging information first.
50 Select the appropriate .elf file (not hex file).
52 DISABLE auto-build
54 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 1.PNG)
56 Choose the appropriate gdb executable - ideally from the same toolchain that you use to build the executable.
58 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 2.PNG)
60 Configure Startup as follows
62 Initialization commands
64 ```
65 target remote localhost:2331
66 monitor interface SWD
67 monitor speed 2000
68 monitor flash device = STM32F103RB
69 monitor flash download = 1
70 monitor flash breakpoints = 1
71 monitor endian little
72 monitor reset
73 ```
76 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 3.PNG)
78 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 4.PNG)
80 It may be useful to specify run commands too:
82 ```
83 monitor reg r13 = (0x00000000)
84 monitor reg pc = (0x00000004)
85 continue
86 ```
88 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 13.PNG)
90 If you use cygwin an additional entry should be shown on the Source tab (not present in this screenshot)
92 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 5.PNG)
94 Nothing to change from the defaults on the Common tab
96 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 6.PNG)
98 Start up the J-Link server in USB mode
100 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 9.PNG)
102 If it connects to your target device it should look like this
104 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 10.PNG)
106 From Eclipse launch the application using the Run/Debug Configurations..., Eclipse should upload the compiled file to the target device which looks like this
108 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 11.PNG)
110 When it's running the J-Link server should look like this.
112 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 12.PNG)
114 Then finally you can use Eclipse debug features to inspect variables, memory, stacktrace, set breakpoints, step over code, etc.
116 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/debugging.PNG)
118 If Eclipse can't find your breakpoints and they are ignored then check your path mappings (if using cygwin) or use the other debugging launcher as follows.  Note the 'Select other...' at the bottom of the configuration window.
120 ![](https://raw.github.com/wiki/cleanflight/cleanflight/images/eclipse-gdb-debugging/config 8 - If breakpoints do not work.PNG)